package com.lovo.service.serviceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lovo.bean.Service;
import com.lovo.bean.ServiceOrder;
import com.lovo.dao.ServiceMapper;
import com.lovo.dao.ServiceOrderMapper;
import com.lovo.service.IServiceOrderService;
import com.lovo.util.SqlSessionUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class ServiceOrderServiceImpl implements IServiceOrderService {

    /**
     * 分页查询所有（包含条件查询）
     * @param pageNo
     * @param pageSize
     * @param serviceOrderQuery
     * @return
     */
    @Override
    public PageInfo<ServiceOrder> getPageByQuery(int pageNo, int pageSize, String serviceOrderQuery) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        ServiceOrderMapper mapper = sqlSession.getMapper(ServiceOrderMapper.class);
        PageHelper.startPage(pageNo,pageSize);
        List<ServiceOrder> list = mapper.selectByQuery (serviceOrderQuery);
        PageInfo<ServiceOrder> page = new PageInfo<ServiceOrder>(list);
        SqlSessionUtil.commit ();
        return page;
    }

//    修改
    @Override
    public boolean updateServiceOrder(ServiceOrder serviceOrder) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        ServiceOrderMapper mapper = sqlSession.getMapper(ServiceOrderMapper.class);

        int n = mapper.updateByPrimaryKeySelective (serviceOrder);

        SqlSessionUtil.commit ();
        return n>0;
    }

//    删除
    @Override
    public boolean delServiceOrder(int n) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        ServiceOrderMapper mapper = sqlSession.getMapper(ServiceOrderMapper.class);

        int flag = mapper.deleteByPrimaryKey (n);

        SqlSessionUtil.commit ();
        return flag>0;
    }
}
